package com.qing.service.impl;

import com.qing.dao.UserLoginLogDao;
import com.qing.domain.Board;
import com.qing.domain.Post;
import com.qing.service.BoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.qing.dao.*;

import java.util.List;

@Service
public class BoardServiceImpl implements BoardService {
    private final BoardDao boardDao;
    @Autowired
    public BoardServiceImpl(BoardDao boardDao){this.boardDao=boardDao;}
    @Override
    public void addBoardByBoard(Board board){ if(board!=null){boardDao.addBoard(board);} }
    public void deleteBoardByBoardName(String boardName){}//空——没有对应Dao层
    public List<Board> listAllBoard(){return boardDao.listAllBoard();}
    /*** 获取指定板块的文章* @param boardId 板块 id* @return 文章列表 */
    public List<Post> listAllPostOfBoard(int boardId){return boardDao.listAllPostsOfBoard(boardId);}
    /*** 通过 id 获取板块 * @param boardId 板块 id * @return 查找到的板块 */
    public Board getBoardByBoardId(int boardId){return boardDao.findBoardByBoardId(boardId);}
    /*** 通过板块名称获取板块* @param boardName 板块名称* @return 查找到的板块  */
    public Board getBoardByBoardName(String boardName){return boardDao.findBoardByBoardName(boardName);}
    /*** 更新板块文章数量 * @param boardId 板块 id*/
    public void updatePostNum(int boardId){
        Board board= boardDao.findBoardByBoardId(boardId);
        board.setBoardPostNum(board.getBoardPostNum()+1);
        boardDao.updateBoardByBoard(board);
    }
    /*** 更新板块信息* @param board 板块实例*/
    public void updateBoardInfo(Board board){boardDao.updateBoardByBoard(board);}
    /*** 删除板块* @param boardId 板块 id*/
    public void deleteBoard(int boardId){boardDao.deleteBoardByBoardId(boardId);}
    public int getBoardPostNum(int boardId){return boardDao.boardPostNum(boardId);}
}
